﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace WeChatParking.Core.Payment.WeixinPay
{
    /// <summary>
    /// 查询订单响应实体
    /// </summary>
   [XmlRoot(Namespace = "", IsNullable = false, ElementName = "xml")]
    public class WxpayQueryOrderResponse
    {

        /// <summary>
        /// 返回状态码 return_code 必填 SUCCESS/FAIL
        /// </summary> 
        [XmlElement("return_code")]
        public string ReturnCode { get; set; }

        /// <summary>
        ///返回信息  return_msg 选填 
        /// </summary>   
        [XmlElement("return_msg")]
        public string ReturnMsg { get; set; }

        //==================以下字段在return_code为success的时候有返回====================
        /// <summary>
        /// 公众账号ID  appid  必填
        /// </summary> 
        [XmlElement("appid")]
        public string AppID { get; set; }

        /// <summary>
        ///  商户号 mch_id 必填 
        /// </summary>  
        [XmlElement("mch_id")]
        public string MchID { get; set; }

        /// <summary>  
        /// 随机字符串 nonce_str 必填 
        /// </summary>
        [XmlElement("nonce_str")]
        public string NonceStr { get; set; }
        /// <summary>
        /// 签名  sign 必填 
        /// </summary>
        [XmlElement("sign")]
        public string Sign { get; set; }

        /// <summary>
        /// 业务结果  result_code 必填  SUCCESS/FAIL
        /// </summary> 
        [XmlElement("result_code")]
        public string ResultCode { get; set; }

        /// <summary>
        /// 错误代码  err_code 选填 
        /// </summary> 
        [XmlElement("err_code")]
        public string ErrCode { get; set; }

        /// <summary>
        /// 错误代码描述  err_code_des 选填
        /// </summary> 
        [XmlElement("err_code_des")]
        public string ErrCodeDes { get; set; }

        //==================以下字段在return_code和result_code为success的时候有返回====================
       
        /// <summary>
        /// 交易状态  trade_state 选填 
        /// </summary> 
        [XmlElement("trade_state")]
        public string TradeState { get; set; }

        /// <summary>
        /// 设备号  device_info 选填 
        /// </summary> 
        [XmlElement("device_info")]
        public string DeviceInfo { get; set; }

        /// <summary>
        /// 用户标识  openid 必填 
        /// </summary>  
        [XmlElement("openid")]
        public string OpenID { get; set; }

        /// <summary>
        /// 是否关注公众账号 is_subscribe 必填   Y-关注，N-未关注
        /// </summary> 
        [XmlElement("is_subscribe")]
        public string IsSubscribe { get; set; }

        /// <summary>
        /// 交易类型 trade_type 必填  JSAPI,NATIVE,MICROPAY,APP
        /// </summary>
        [XmlElement("trade_type")]
        public string TradeType { get; set; }

        /// <summary>
        /// 付款银行 bank_type 必填 
        /// </summary> 
        [XmlElement("bank_type")]
        public string BankType { get; set; }

        /// <summary>
        /// 总金额 total_fee 必填  
        /// </summary>
        [XmlElement("total_fee")]
        public int TotalFee { get; set; }

        /// <summary>
        /// 现金券金额 coupon_fee 选填  
        /// </summary>
        [XmlElement("coupon_fee")]
        public int? CouponFee { get; set; }

        /// <summary>
        /// 货币种类 fee_type 选填 
        /// </summary> 
        [XmlElement("fee_type")]
        public string FeeType { get; set; }


        /// <summary>
        /// 现金支付金额 cash_fee 必填 
        /// </summary> 
        [XmlElement("cash_fee")]
        public int CashFee { get; set; }

        /// <summary>
        /// 微信支付订单 transaction_id 必填 
        /// </summary>  
        [XmlElement("transaction_id")]
        public string TransationID { get; set; }
        /// <summary>
        /// 商户订单号 out_trade_no 必填 
        /// </summary>
        [XmlElement("out_trade_no")]
        public string OutTradeNo { get; set; }
        /// <summary>
        /// 商家数据包 attach 选填 
        /// </summary>
        [XmlElement("attach")]
        public string Attach { get; set; }

        /// <summary>
        /// 支付完成时间 time_end 必填    yyyyMMddhhmmss
        /// </summary> 
        [XmlElement("time_end")]
        public string TimeEnd { get; set; }

        public  IDictionary<string, string> GetParameters()
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("return_code", this.ReturnCode);
            parameters.Add("return_msg", this.ReturnMsg);
            parameters.Add("appid", this.AppID);
            parameters.Add("mch_id", this.MchID);
            parameters.Add("nonce_str", this.NonceStr);
            parameters.Add("sign", this.Sign);

            parameters.Add("result_code", this.ResultCode);
            parameters.Add("err_code", this.ErrCode);
            parameters.Add("err_code_des", this.ErrCodeDes);
            parameters.Add("trade_state", this.TradeState);

            parameters.Add("device_info", this.DeviceInfo);
            parameters.Add("openid", this.OpenID);
            parameters.Add("is_subscribe", this.IsSubscribe);
            parameters.Add("trade_type", this.TradeType);

            parameters.Add("bank_type", this.BankType);
            parameters.Add("total_fee", this.TotalFee.ToString());
            parameters.Add("coupon_fee", this.CouponFee.ToString());
            parameters.Add("fee_type", this.FeeType);

            parameters.Add("cash_fee", this.CashFee.ToString());
            parameters.Add("transaction_id", this.TransationID);
            parameters.Add("out_trade_no", this.OutTradeNo);
            parameters.Add("attach", this.Attach);
            parameters.Add("time_end", this.TimeEnd);

            return parameters;
        }

    }
}
